<template>
    <div>
        <h2>增加会员等级</h2>
        <table class="table table-bordered">
            <tr>
                <td>会员等级名称</td>
                <td>
                    <input type="text" placeholder="请输入会员等级名称" v-model="state.memberLevelName">
                </td>
            </tr>
            <tr>
                <td>会员等级编号</td>
                <td><input type="text" placeholder="请输入会员等级编号" v-model="state.memberLevelBianhao"></td>
            </tr>
            <tr>
                <td>会员等级最高价</td>
                <td>
                    <input type="text" placeholder="请输入会员等级最高价" v-model="state.highMoney" >
                   
                </td>
            </tr>
            <tr>
                <td>会员等级最低价</td>
                <td>
                    <input type="text" placeholder="请输入会员等级最低价" v-model="state.lowMoney" >
                </td>
            </tr>
            <tr>
                <td>添加时间</td>
                <td>
                    <input type="date" v-model="state.addTime"  >
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="确认" @click="add">
                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios  from 'axios';
import { reactive,toRefs,onMounted } from 'vue';
import { useRouter,useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
const data = reactive({
    state:{
"memberLevelName": "房价折扣",
  "memberLevelBianhao": "1001",
  "highMoney": 0,
  "lowMoney": 0,
  "addTime": "2024-09-01",
  "state": 0,
  "isDeleted": false
    }
})

const {state} = toRefs(data);

//添加
const add = () => {
    if(state.value.memberLevelName=='')
    {
        alert('会员等级名称不能为空');
            return;
    }
    if(state.value.memberLevelBianhao=='')
    {
        alert('会员等级编号不能为空');
            return;
    }
    if(state.value.highMoney=='')
    {
        alert('会员等级最高价不能为空');
            return;
    }
    if(isNaN(Number(state.value.highMoney)))
    {
        alert('会员等级最高价必须填数字类型');
            return;
    }
    if(state.value.lowMoney=='')
    {
        alert('会员等级最低价不能为空');
            return;
    }
    if(isNaN(Number(state.value.lowMoney)))
    {
        alert('会员等级最低价必须填数字类型');
            return;
    }
    if(state.value.addTime=='')
    {
        alert('添加时间不能为空');
            return;
    }
    axios({
        url:'/api/Member/AddMemberLevel',
        method:'post',
        data:state.value
    })
    .then(res => {
        console.log(res);
        if(res.data.data>0)
        {
            alert('添加成功');
            router.push('/ShowLevel');
        }
        else if(res.data.data==0)
        {
            alert('会员等级名称不能重复');
            return;
        }
        else{
            alert('添加失败');
            return;
        }
    })
    .catch(err => {
        console.log(err);
    })
}

</script>

<style scoped>

</style>